package android.game;
import java.util.List;

import android.util.Log;



import framework.Game;
import framework.Graphics;
import framework.Input.TouchEvent;
import framework.Screen;
public class MainMenuScreen extends Screen {
	
	public MainMenuScreen(Game game) {
		super(game);
	}
	@Override
	public void update(float deltaTime) {
		Graphics g = game.getGraphics();
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();   
		int len = touchEvents.size();
		for(int i=0;i<len;i++){
			TouchEvent event = touchEvents.get(i);
			if(event.type == TouchEvent.TOUCH_UP){
				 if(inBounds(event, 90, 220, 150, 35)) {
					 Assets.menuClick.play(1);
					 game.setScreen(new HelpScreen(game));
	             }
				 if(inBounds(event,90, 155, 150, 35)){
					 Assets.menuClick.play(1);
					 game.setScreen(new GameScreen(game));
				 }
				 if(inBounds(event,110,290,105,35)){
					 Assets.menuClick.play(1);
					 game.setScreen(new HighscoreScreen(game));
				 }
				 if(inBounds(event,90,360,150,35)){
					 Assets.menuClick.play(1);
					 Settings.save(game.getFileIO());
					System.exit(0);
				 }
			}
		}
		
	}
	private boolean inBounds(TouchEvent event, int x, int y, int width, int height) {
        if(event.x > x && event.x < x + width - 1 && 
           event.y > y && event.y < y + height - 1) 
            return true;
        else
            return false;
    }
	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawPixmap(Assets.bg_default, 0, 0);
		g.drawPixmap(Assets.mainMenu, 0, 0);
		if(Settings.soundEnabled){
			Assets.zombieFatWalk.setLooping(false);
			Assets.zombieFatWalk.setVolume(1);
			Assets.zombieFatWalk.play();
			Assets.zombieFatWalk.stop();
		}
	}
	
	@Override
	public void pause() {
		// TODO Auto-generated method stub
		 Settings.save(game.getFileIO());
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
	
}
